﻿using Infraestructure.Data.MainModule.Repositories;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Infraestructure.Data.MainModule.UnitOfWork;
using Infraestructure.CrossCutting.Logging;
using Domain.MainModule.Entities;
using Domain.Core.Specification;
using Domain.MainModule.CustomersMTS;

namespace Infraestructure.Data.MainModule.Tests
{
    /// <summary>
    ///This is a test class for CustomerMTSRepositoryTest and is intended
    ///to contain all CustomerMTSRepositoryTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CustomerMTSRepositoryTest : CustomRepositoryTestsBase<CustomerMTS, User>
    {
        private TestContext testContextInstance;
        
        string customerMTSFirstName = "Charles";
        string customerMTSLastName = "Xavier";
        string customerMTSFirstSurName = "X-Men";
        string customerMTSLastSurName = "X-Men";

        public override System.Linq.Expressions.Expression<Func<CustomerMTS, bool>> FilterExpression
        {
            get { return a => a.UserId == TestConstants.Instance.CUSTOMER_MTS_ID; }
        }

        public override System.Linq.Expressions.Expression<Func<CustomerMTS, Guid>> OrderByExpression
        {
            get { return a => a.UserId; }
        }

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindCustomerMTS_Invoke_NullSpecThrowNewArgumentNullException_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerMTSRepository repository = new CustomerMTSRepository(context, traceManager);

            //Act
            repository.FindCustomerMTS(null);
        }

        #region CustomerMTSUserIdSpecification

        [TestMethod()]
        public void FindCustomerMTSByUserId_Invoke_InvalidUserIdReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerMTSRepository repository = new CustomerMTSRepository(context, traceManager);
            CustomerMTS customerMTS;

            Guid invalidId = new Guid("11111111-1111-1111-1111-111111111111");
            CustomerMTSUserIdSpecification spec = new CustomerMTSUserIdSpecification(invalidId);

            //Act
            customerMTS = repository.FindCustomerMTS(spec);

            //Assert
            Assert.IsNull(customerMTS);
        }

        /// <summary>
        ///A test for FindCustomerMTS
        ///</summary>
        [TestMethod()]
        public void FindCustomerMTSByUserId_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerMTSRepository repository = new CustomerMTSRepository(context, traceManager);
            CustomerMTS actual;
            CustomerMTSUserIdSpecification specification = new CustomerMTSUserIdSpecification(TestConstants.Instance.USER_ID);

            //Act
            actual = repository.FindCustomerMTS(specification);

            //Assert 
            Assert.IsNotNull(actual);
        }

        #endregion

        #region CustomerMTSNameSpecification

        [TestMethod()]
        public void FindCustomerMTSByName_Invoke_InvalidUserIdReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerMTSRepository repository = new CustomerMTSRepository(context, traceManager);
            CustomerMTS customerMTS;

            CustomerMTSNameSpecification spec = new CustomerMTSNameSpecification(string.Empty, "mojojojo", "lala", "moco");

            //Act
            customerMTS = repository.FindCustomerMTS(spec);

            //Assert
            Assert.IsNull(customerMTS);
        }

        /// <summary>
        ///A test for FindCustomerMTS
        ///</summary>
        [TestMethod()]
        public void FindCustomerMTSByName_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICustomerMTSRepository repository = new CustomerMTSRepository(context, traceManager);
            CustomerMTS actual;
            CustomerMTSNameSpecification specification = new CustomerMTSNameSpecification(customerMTSFirstName, customerMTSLastName, customerMTSFirstSurName, customerMTSLastSurName);

            //Act
            actual = repository.FindCustomerMTS(specification);

            //Assert 
            Assert.IsNotNull(actual);
        }

        #endregion
    }
}
